<template>
  <div>
      <table>
          <tr>
              <td>名称</td>
              <td>数量</td>
              <td>积分</td>
              <td>操作</td>
          </tr>
          <tr v-for="i in giftlist" :key="i">
              <td>{{i.name}}</td>
              <td>{{i.num}}</td>
              <td>{{i.d_integral}}</td>
              <td><button @click="rate(i.id)">兑换</button></td>
          </tr>
      </table>
  </div>
</template>

<script>
import axios from '../../http/axios'
export default {
data () {
    return {
        giftlist:[],
        userid:localStorage.getItem('userid')
    }
},
methods: {
    get_gift(){
        axios('/gift','get').then(res=>{
            console.log(res)
            this.giftlist=res.list
        })
    },
    // 兑换礼品
    rate(id){
        axios('/gift?id='+id,'post',{'userid':this.userid}).then(res=>{
            console.log(res)
            if (res.code==200){
                alert(res.msg)
                this.get_gift()
            }
        })
    }
},
mounted () {
    this.get_gift()
}
}
</script>

<style>

</style>